package com.leetcode.demo3Solution.java;

public class demo121 {
    public static void main(String[] args) {
        int[] nums={7,6,4,1};
        System.out.println("买卖股票最好时机:"+maxProfit(nums));
    }

    public static int maxProfit(int[] prices) {

        //1,遍历太耗时间 相邻两位数作比较（好傻啊）
     /*   if(prices.length==1 || prices.length == 0)
            return 0;
        int ans=0,sum;
        for(int i=0;i<prices.length;i++){
            int min=prices[i];
            for(int j=i+1;j<prices.length;j++){
                 int max=prices[j];
                 if(max>min){
                     sum=max-min;
                     ans=Math.max(ans,sum);
                 }
            }
        }*/
     //2.遍历  找出当前轮数的最小数和左侧的最大数直接比较
       /* if(prices.length==1 || prices.length == 0)
            return 0;
        int ans=0,sum;;
        for(int i=0;i<prices.length;i++){
            int min=prices[i];
            int max=0;
            for(int j=i+1;j<prices.length;j++){
              if(max<prices[j])
                  max=prices[j];
            }
            if(max>min){
            sum=max-min;
            ans=Math.max(ans,sum);
            }
        }
        return ans;*/
       return 1;
    }

}
